package com.example.deal.listner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;

/**
 * 
 * @author Dustyone
 * @DateTime 2019年3月22日 下午5:19:42
 *
 */
@Component
public class ApolloConfigChangeListener1 {

	private static final Logger logger = LoggerFactory.getLogger(ApolloConfigChangeListener1.class);
	
	//使用Apollo Client API获取配置信息
	Config config = ConfigService.getAppConfig(); // config instance is singleton for each namespace and is never null

	@ApolloConfigChangeListener(value = {ConfigConsts.NAMESPACE_APPLICATION,"dustyone.yml","customized.properties"},
		      interestedKeyPrefixes= ("crm.*"))
	public void onChange(ConfigChangeEvent changeEvent) {
		logger.info("Changes for namespace " + changeEvent.getNamespace());
		for (String key : changeEvent.changedKeys()) {
			ConfigChange change = changeEvent.getChange(key);
			logger.info(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s",
					change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType()));
		}
	}
	
}
